package com.AJava1710D.bingfabao.cyc;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * 作者: LCG
 * 日期: 2020/6/23 11:44
 * 描述:
 */
public class TestRun2 implements Runnable {

    private CyclicBarrier cyclicBarrier;

    private long time;

    public TestRun2(CyclicBarrier cyclicBarrier, long time) {
        this.cyclicBarrier = cyclicBarrier;
        this.time = time;
    }

    @Override
    public void run() {

        try {
            Thread.sleep(time);
            System.out.println(Thread.currentThread().getName()+"========到达起跑线");
            cyclicBarrier.await();
            System.out.println("=====起跑=====");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }

    }
}
